package com.ruoyi.quartz.task;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.quartz.domain.Wddqtx;
import com.ruoyi.quartz.service.IWddqtxService;
import com.ruoyi.quartz.util.AliyunSmsUtils;

/**
 * 定时任务调度测试
 * 
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask{
	
	@Autowired
    private IWddqtxService wddqtxService;
	
    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }
    
    public void wddqtx(String tels){
    	try {
//    		System.out.println("执行执行文档到期提醒：" + tels);
            Wddqtx gcWddqtx = new Wddqtx();
            gcWddqtx.setDeleteFlag(1);
            List<Wddqtx> txlis = wddqtxService.selectGcWddqtxList(gcWddqtx);
            Calendar calendar = Calendar.getInstance();
            for(Wddqtx tx:txlis){
            	int day = tx.getAlertDays();//到期提醒天数
            	Date yxqz = tx.getYxqz();//有效期至
            	Date xgsj = DateUtils.dayAddAndSub(calendar.DATE, day);//当前时间增加时间后
            	
//            	System.out.println("有效期至:"+DateUtils.dateTime(yxqz));
//            	System.out.println("当前时间增加时间后:"+DateUtils.dateTime(xgsj));
            	int difDay = DateUtils.differentDaysByMillisecond(yxqz, xgsj);//相差时间
            	if(difDay<=0){
            		List<String> phones = Arrays.asList(tels.split(","));
            		AliyunSmsUtils.returnSmsDqtx(phones);
            		break;
            	}
            	
            }
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
//			System.out.println("执行文档到期提醒有错，请联系管理员");
		}
    }

    public void ryNoParams()
    {
        System.out.println("执行无参方法");
    }
}
